//
//  SMACMusicChangeController.swift
//  SmiraAiChat
//
//  Created by mumu on 2024/9/23.
//

import UIKit

class SMACMusicChangeController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "bgHomeCellID", for: indexPath)
        var imgView = cell.viewWithTag(20) as? UIImageView
        if imgView == nil {
            imgView = UIImageView()
            
            imgView?.tag = 20
            imgView?.layer.cornerRadius = 20
            imgView?.layer.masksToBounds = true
            imgView?.contentMode = .scaleAspectFill
            
            cell.contentView.addSubview(imgView!)
            
            imgView!.snp.makeConstraints { make in
                make.top.bottom.equalToSuperview()
                make.left.right.equalToSuperview().inset(50.x_bili)
            }
        }
        imgView?.image = UIImage.init(named: "")
        return cell
    }
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let nowpage = Int(scrollView.contentOffset.x/(SMACCommen.scrwid_SMAC - 40.x_bili))
        self.pageView_SMAC.currentPage = nowpage
    }
    
    lazy var pageView_SMAC: UIPageControl = {
        let page = UIPageControl.init()
        page.currentPage = 0
        page.numberOfPages = 4
        page.currentPageIndicatorTintColor = .gray
        page.pageIndicatorTintColor = .black
        return page
    }()
    
    lazy var showbgView: UICollectionView = {
        let smaclayout = UICollectionViewFlowLayout()
        smaclayout.scrollDirection = .horizontal
        smaclayout.itemSize = CGSize(width: (SMACCommen.scrwid_SMAC - 40.x_bili) , height: 378.x_bili)
        smaclayout.minimumLineSpacing = 0
        smaclayout.minimumInteritemSpacing = 0
        smaclayout.sectionInset = UIEdgeInsets.zero
        let collection = UICollectionView(frame: .zero, collectionViewLayout:smaclayout)
        collection.isPagingEnabled = true
        collection.backgroundColor = .clear
        collection.delegate = self
        collection.dataSource = self
        collection.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "bgHomeCellID")
        collection.showsHorizontalScrollIndicator = false
        return collection
    }()
    
    private let minename = UILabel.init()
    lazy var dismissBtn_SMAC: UIButton = {
        let btn = UIButton.init()
        btn.setImage(UIImage.init(named: "icon_close"), for: .normal)
        btn.addTarget(self, action: #selector(dismissLast_AMSC), for: .touchUpInside)
        return btn
    }()
    lazy var saveBtn_SMAC: UIButton = {
        let saveBtn = UIButton.init()
        saveBtn.layer.cornerRadius = 12
        saveBtn.backgroundColor = UIColor(red: 0.02, green: 0.02, blue: 0.02, alpha: 1)
        saveBtn.setTitle("Save", for: .normal)
        saveBtn.setTitleColor( .white, for: .normal)
        saveBtn.titleLabel?.font =  UIFont(name: "HarmonyOS Sans Medium", size: 16)
        return saveBtn
    }()
    @objc func dismissLast_AMSC() {
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let msuicavator = UIImageView.init(image: UIImage.init(named: ""))
        minename.text = "Galactic Muse"
        minename.font = UIFont(name: "HarmonyOS Sans Bold", size: 17)
        
        
        let whiteBg = UIView.init()
        whiteBg.backgroundColor = .white
        whiteBg.layer.cornerRadius = 32
        whiteBg.layer.masksToBounds = true
        
        view.addSubview(whiteBg)
        whiteBg.addSubview(msuicavator)
        whiteBg.addSubview(minename)
        whiteBg.addSubview(dismissBtn_SMAC)
        
        whiteBg.addSubview(saveBtn_SMAC)
        whiteBg.addSubview(pageView_SMAC)
    
    }
    

}
